import { Component, OnInit } from '@angular/core';
import {
  AbstractControl,
  FormBuilder,
  FormGroup,
  Validators
} from '@angular/forms';

@Component({
  selector: 'app-end-match',
  templateUrl: './end-match.component.html',
  styleUrls: ['./end-match.component.less']
})
export class EndMatchComponent implements OnInit {
  validateForm: FormGroup;
  final = 0;
  final_goals = '';
  valid(): boolean {
    for (const i in this.validateForm.controls) {
      this.validateForm.controls[ i ].markAsDirty();
      this.validateForm.controls[ i ].updateValueAndValidity();
    }
    return this.validateForm.valid;
  }

  constructor(private fb: FormBuilder) {
  }

  ngOnInit(): void {
    this.validateForm = this.fb.group({
      final: [ null, [ Validators.required ] ],
      final_goals: [ null, [ Validators.required ] ],
    });
  }

  getValue() : {final: number, final_goals: string}{
    return {
        final: this.final,
        final_goals: this.final_goals
    }
  }
}
